import FonctionSetCover as F
import Producteur as P
import Set as S
import Consommateur as C


TabClient=[]
TabProd=[]
TabProd.append(P.Producteur("P1","Belleville-sur-Loire",47.506113,2.851424,30.9,1122612,0,10))
TabProd.append(P.Producteur("P2","Braud-et-Saint-Louis",45.248611,-0.623889,30.9,979534,0,10))
TabProd.append(P.Producteur("P3","Saint-Vulbas",45.8339,5.2931,30.9,665863,0,10))
TabProd.append(P.Producteur("P4","Cattenom",49.4067,6.2456,30.9,5090275,0,10))
TabProd.append(P.Producteur("P5","Avoine",47.205833,0.183889,30.9,4925185,0,10))
TabProd.append(P.Producteur("P6","Chooz",50.1042,4.8078,30.9,467755,0,10))
TabProd.append(P.Producteur("P7","Civaux",46.445278,0.666944,30.9,126569,0,10))
TabProd.append(P.Producteur("P8","Cruas",44.657778,4.763611,30.9,126569,0,10))
TabProd.append(P.Producteur("P9","Dampierre-en-Burly",47.760833,2.518333,30.9,126569,0,10))
TabProd.append(P.Producteur("P10","Fessenheim",47.9156,7.5367,30.9,126569,0,10))
TabProd.append(P.Producteur("P11","Flamanville",49.531389,-1.865278,30.9,126569,0,10))
TabProd.append(P.Producteur("P12","Golfech",44.114722,0.851944,30.9,126569,0,10))
TabProd.append(P.Producteur("P13","Gravelines",50.9858,2.1283,30.9,126569,0,10))
TabProd.append(P.Producteur("P14","Nogent-sur-Seine",48.494167,3.503333,30.9,126569,0,10))
TabProd.append(P.Producteur("P15","Paluel",49.8336,0.6289,30.9,126569,0,10))
TabProd.append(P.Producteur("P16","Saint-Martin-en-Campagne",49.957778,1.2225,30.9,126569,0,10))
TabProd.append(P.Producteur("P17","Saint-Alban-du-Rhone",45.4275,4.756111,30.9,126569,0,10))
TabProd.append(P.Producteur("P18","Saint-Laurent-Nouan",47.7175,1.6125,30.9,126569,0,10))
TabProd.append(P.Producteur("P19","Pierrelatte",44.378333,4.696389,30.9,126569,0,10))


TabClient.append(C.Consommateur(0.837758041,0.0523598776,"Paris","Ile-de-France",22234105,1667557875))
TabClient.append(C.Consommateur(0.7504915784,0,"Marseille","Provence-Alpes-Cote dAzur",850602,63795150))
TabClient.append(C.Consommateur(0.7853981634,0.0523598776,"Lyon","Rhone-Alpes",479803,35985225))
TabClient.append(C.Consommateur(0.7504915784,0.0174532925,"Toulouse","Midi-Pyrenees",440204,33015300))
TabClient.append(C.Consommateur(0.7504915784,0.0698131701,"Nice","Provence-Alpes-Cete dAzur",340735,25555125))
TabClient.append(C.Consommateur(0.8203047484,0,"Nantes","Pays de la Loire",282047,21153525))
TabClient.append(C.Consommateur(0.837758041,0.0698131701,"Strasbourg","Alsace",271708,20378100))
TabClient.append(C.Consommateur(0.7504915784,0.0872664626,"Montpellier","Languedoc-Roussillon",255080,19131000))
TabClient.append(C.Consommateur(0.7679448709,0.0872664626,"Bordeaux","Aquitaine",236725,17754375))
TabClient.append(C.Consommateur(0.872664626,0.0872664626,"Lille","Nord-Pas-de-Calais",226827,17012025))
TabClient.append(C.Consommateur(0.837758041,0,"Rennes","Bretagne",206604,15495300))
TabClient.append(C.Consommateur(0.8552113335,0.0698131701,"Reims","Champagne-Ardenne",180842,13563150))
TabClient.append(C.Consommateur(0.8552113335,0,"Le Havre","Haute-Normandie",177259,13294425))
TabClient.append(C.Consommateur(0.7853981634,0.0872664626,"Saint-Etienne","Rhone-Alpes",171961,12897075))
TabClient.append(C.Consommateur(0.7504915784,-0.0698131701,"Toulon","Provence-Alpes-Cote dAzur",165514,12413550))
TabClient.append(C.Consommateur(0.7853981634,0.0698131701,"Grenoble","Rhone-Alpes",155632,11672400))
TabClient.append(C.Consommateur(0.8203047484,0.0174532925,"Dijon","Bourgogne",152110,11408250))
TabClient.append(C.Consommateur(0.8203047484,0.0523598776,"Angers","Pays de la Loire",147305,11047875))
TabClient.append(C.Consommateur(0.7853981634,0,"Villeurbanne","Rhone-Alpes",144751,10856325))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Le Mans","Pays de la Loire",142281,10671075))
TabClient.append(C.Consommateur(0.7504915784,0.1047197551,"Aix-en-Provence","Provence-Alpes-Cote dAzur",141895,10642125))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Brest","Bretagne",141315,10598625))
TabClient.append(C.Consommateur(0.7504915784,0.1047197551,"Nimes","Languedoc-Roussillon",140747,10556025))
TabClient.append(C.Consommateur(0.7853981634,0.0174532925,"Limoges","Limousin",139216,10441200))
TabClient.append(C.Consommateur(0.7853981634,0.034906585,"Clermont-Ferrand","Auvergne",138588,10394100))
TabClient.append(C.Consommateur(0.8203047484,0.1221730476,"Tours","Centre",135218,10141350))
TabClient.append(C.Consommateur(0.8552113335,0.0174532925,"Amiens","Picardie",133998,10049850))
TabClient.append(C.Consommateur(0.8552113335,0,"Metz","Lorraine",121841,9138075))
TabClient.append(C.Consommateur(0.7330382858,0.1047197551,"Perpignan","Languedoc-Roussillon",117905,8842875))
TabClient.append(C.Consommateur(0.8203047484,0.034906585,"Besancon","Franche-Comte",117392,8804400))
TabClient.append(C.Consommateur(0.8203047484,0.034906585,"Orleans","Centre",113224,8491800))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Boulogne-Billancourt","Ile-de-France",113085,8481375))
TabClient.append(C.Consommateur(0.8203047484,0.0523598776,"Mulhouse","Alsace",111156,8336700))
TabClient.append(C.Consommateur(0.8552113335,0.034906585,"Rouen","Haute-Normandie",110688,8301600))
TabClient.append(C.Consommateur(0.8203047484,0.0523598776,"Cean","Basse-Normandie",109312,8198400))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Nancy","Lorraine",106318,7973850))
TabClient.append(C.Consommateur(0.837758041,0.0698131701,"Saint-Denis","Ile-de-France",105749,7931175))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Montreuil","Ile-de-France",103192,7739400))
TabClient.append(C.Consommateur(0.837758041,0,"Argenteuil","Ile-de-France",102844,7713300))
TabClient.append(C.Consommateur(0.872664626,0.034906585,"Roubaix","Nord-Pas-de-Calais",95028,7127100))
TabClient.append(C.Consommateur(0.8901179185,0.034906585,"Dunkerque","Nord-Pas-de-Calais",92923,6969225))
TabClient.append(C.Consommateur(0.872664626,0.034906585,"Tourcoing","Nord-Pas-de-Calais",92389,6929175))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Nanterre","Ile-de-France",89966,6747450))
TabClient.append(C.Consommateur(0.7504915784,0,"Avignion","Provence-Alpes-Cote dAzur",89592,6719400))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Creteil","Ile-de-France",89359,6701925))
TabClient.append(C.Consommateur(0.8028514559,0.034906585,"Poitiers","Poitou-Charentes",88795,6659625))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Courbevoie","Ile-de-France",86945,6520875))
TabClient.append(C.Consommateur(0.837758041,0.1221730476,"Versailles","Ile-de-France",86477,6485775))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Vitry-sur-Seine","Ile-de-France",85380,6403500))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Colombes","Ile-de-France",84572,6342900))
TabClient.append(C.Consommateur(0.7504915784,-0.0174532925,"Pau","Aquitaine",82763,6207225))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Aulnay-sous-Bois","Ile-de-France",82525,6189375))
TabClient.append(C.Consommateur(0.837758041,0.0174532925,"Asnieres-sur -Seine","Ile-de-France",81603,6120225))
TabClient.append(C.Consommateur(0.837758041,0.1221730476,"Rueil-Malmaison","Ile-de-France",79065,5929875))
TabClient.append(C.Consommateur(0.7504915784,0.0523598776,"Antibes","Provence-Alpes-Cote dAzur",75553,5666475))
TabClient.append(C.Consommateur(0.837758041,0.1221730476,"Saint-Maur-des-Fosses","Ile-de-France",75251,5643825))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Champigny-Sur-Marne","Ile-de-France",75090,5631750))
TabClient.append(C.Consommateur(0.8028514559,0.034906585,"La Rochelle","Poitou-Charentes",74707,5603025))
TabClient.append(C.Consommateur(0.837758041,0,"Aubervilliers","Ile-de-France",74701,5602575))
TabClient.append(C.Consommateur(0.872664626,-0.034906585,"Calais","Nord-Pas-de-Calais",74336,5575200))
TabClient.append(C.Consommateur(0.7504915784,0.0698131701,"Cannes","Provence-Alpes-Cote dAzur",73372,5502900))
TabClient.append(C.Consommateur(0.7504915784,0.1396263402,"Beziers","Languedoc-Roussillon",70957,5321775))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Colmar","Alsace",67214,5041050))
TabClient.append(C.Consommateur(0.8203047484,0.0523598776,"Bourges","Centre",66786,5008950))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Drancy","Ile-de-France",66670,5000250))
TabClient.append(C.Consommateur(0.7679448709,0.034906585,"Merignac","Aquitaine",66488,4986600))
TabClient.append(C.Consommateur(0.8203047484,-0.0698131701,"Saint-Nazaire","Pays de la Loire",66348,4976100))
TabClient.append(C.Consommateur(0.7679448709,0.0872664626,"Valence","Rhone-Alpes",64367,4827525))
TabClient.append(C.Consommateur(0.7155849933,0.034906585,"Ajaccio","Corse",64306,4822950))
TabClient.append(C.Consommateur(0.837758041,0.0698131701,"Issy-les-Moulineaux","Ile-de-France",64027,4802025))
TabClient.append(C.Consommateur(0.872664626,0.034906585,"Villeneuve-dAscq","Nord-Pas-de-Calais",63844,4788300))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Levallois-Perret","Ile-de-France",63436,4757700))
TabClient.append(C.Consommateur(0.837758041,0.0698131701,"Noisy-le-Grand","Ile-de-France",63405,4755375))
TabClient.append(C.Consommateur(0.8203047484,0.034906585,"Quimper","Bretagne",63387,4754025))
TabClient.append(C.Consommateur(0.7504915784,-0.0523598776,"La Seyne-sur-Mer","Provence-Alpes-Cote dAzur",61514,4613550))
TabClient.append(C.Consommateur(0.837758041,0,"Antony","Ile-de-France",61393,4604475))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Troyes","Champagne-Ardenne",61188,4589100))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Neuilly-sur-Seine","Ile-de-France",60501,4537575))
TabClient.append(C.Consommateur(0.837758041,0,"Sarcelles","Ile-de-France",59421,4456575))
TabClient.append(C.Consommateur(0.7853981634,0.0872664626,"Venissieux","Rhone-Alpes",58643,4398225))
TabClient.append(C.Consommateur(0.837758041,0.0174532925,"Clichy","Ile-de-France",58200,4365000))
TabClient.append(C.Consommateur(0.8203047484,0.0523598776,"Lorient","Bretagne",57812,4335900))
TabClient.append(C.Consommateur(0.7679448709,0.034906585,"Pessac","Aquitaine",57593,4319475))
TabClient.append(C.Consommateur(0.837758041,0.1047197551,"Ivry-sur-Seine","Ile-de-France",57254,4294050))
TabClient.append(C.Consommateur(0.8552113335,0.034906585,"Cergy","Ile-de-France",57247,4293525))
TabClient.append(C.Consommateur(0.8028514559,0,"Niort","Poitou-Charentes",56878,4265850))
TabClient.append(C.Consommateur(0.7853981634,0.034906585,"Chambery","Rhone-Alpes",56476,4235700))
TabClient.append(C.Consommateur(0.7679448709,0.034906585,"Montauban","Midi-Pyrenees",56126,4209450))
TabClient.append(C.Consommateur(0.8552113335,0.034906585,"Saint-Quentin","Picardie",55971,4197825))
TabClient.append(C.Consommateur(0.837758041,0.1047197551,"Vilejuif","Ile-de-France",55250,4143750))
TabClient.append(C.Consommateur(0.7504915784,-0.034906585,"Hyeres","Provence-Alpes-Cote dAzur",54686,4101450))
TabClient.append(C.Consommateur(0.8552113335,0.034906585,"Beauvais","Picardie",54461,4084575))
TabClient.append(C.Consommateur(0.8203047484,0.034906585,"Cholet","Pays de la Loire",54121,4059075))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Epinay-sur-Seine","Ile-de-France",53577,4018275))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Bondy","Ile-de-France",53448,4008600))
TabClient.append(C.Consommateur(0.837758041,-0.0174532925,"Fontenay-sous-Bois","Ile-de-France",53258,3994350))
TabClient.append(C.Consommateur(0.7504915784,0.1047197551,"Arles","Provence-Alpes-Cote dAzur",52979,3973425))
TabClient.append(C.Consommateur(0.8203047484,0.034906585,"Vannes","Bretagne",52683,3951225))
TabClient.append(C.Consommateur(0.837758041,0.1047197551,"Chelles","Ile-de-France",52636,3947700))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Maisons-Alfort","Ile-de-France",52619,3946425))
TabClient.append(C.Consommateur(0.837758041,0.0523598776,"Clamart","Ile-de-France",52569,3942675))
TabClient.append(C.Consommateur(0.837758041,0.0174532925,"Evry","Ile-de-France",52403,3930225))
TabClient.append(C.Consommateur(0.8028514559,0,"La Roche-sur-Yon","Pays de la Loire",52234,3917550))
TabClient.append(C.Consommateur(0.7504915784,0.034906585,"Frejus","Provence-Alpes-Cote dAzur",52203,3915225))
TabClient.append(C.Consommateur(0.837758041,0.1047197551,"Pantin","Ile-de-France",52161,3912075))
TabClient.append(C.Consommateur(0.7504915784,0.1047197551,"Grasse","Provence-Alpes-Cote dAzur",52019,3901425))
TabClient.append(C.Consommateur(0.837758041,0.034906585,"Sartrouville","Ile-de-France",51459,3859425))
TabClient.append(C.Consommateur(0.7504915784,0,"Narbonne","Languedoc-Roussillon",51227,3842025))
TabClient.append(C.Consommateur(0.8552113335,0,"Evreux","Haute-Normandie",51193,3839475))
TabClient.append(C.Consommateur(0.8203047484,0,"Laval","Pays de la Loire",51182,3838650))
TabClient.append(C.Consommateur(0.837758041,0,"Le Blanc-Mesnil","Ile-de-France",51106,3832950))
TabClient.append(C.Consommateur(0.7853981634,0,"Annecy","Rhone-Alpes",50254,3769050))
TabClient.append(C.Consommateur(0.8203047484,0,"Belfort","Franche-Comte",50199,3764925))
TabClient.append(C.Consommateur(0.837758041,0,"Sevran","Ile-de-France",50021,3751575))





""" Test Unitaire"""

"""F.distance OK"""
print("Distance Critique")
print(F.findCriticalDistance(TabProd,TabClient))

"""generation des set Personnalises"""


T1=F.generateSetSimplified(TabProd,TabClient)
print("Sets generes\n")

print("vzrification de asClient")
for s in T1:
    for c in s.TabClient:
        if (s.asClient(c)==0):
            print("asClient nest pas bien implemente")
            
con=1
index=0
for client in TabClient:
    index+=1
    c=0
    for s in T1:
        if(s.asClient(client)==1):
            c=1
            break
    if(c==0):
        con=0
        print("IL y a des clients non pourvus")
        print(client.name)
        print(client.key)
        print("Index in TabClient")
        print(index)
        break
if(con==1):
    print("Tous les clients ont un producteur attitres")

"""T2=F.linearRelaxation(T1, TabClient)
print("Fin relaxation lineaire")
print(T2)

T3=F.repairingFinal(T1,F.decisionToPickSet(T2), TabClient)
print(T2)
T3=F.repairingFinal(T1,F.decisionToPickSet(T2), TabClient)

print("Solution de la relaxation lineaire initiale\n")
print(T2)
print("Choix en fonction des probabilite allouee avec la rel. Lin\n")
T4=F.decisionToPickSet(T2)
print(T4)
print("Choix 'repare', tous les clients sont couverts\n")
T5=F.decisionToPickSet(T3)
print(T5)


acc=0
for i in range(len(T2)):
    if (T5[i]!=T4[i]):
        acc+=1

print("Nombre de choix repare:")
print(acc)
print("Nombre de Set envisages:")
print(len(T5))

"""
T2=F.greedyAlgorithm(T1,TabClient)
print(T2)

print(len(T1[0].TabClient))



for i in TabProd:
    print("je change de prod")
    for j in TabClient:
        print(F.distance(i,j))
